using System;
using System.Collections;
using System.Data.Linq.Mapping;
using System.Runtime.Serialization;
using Portal.Data.Helper;
using Portal.Core.Helper;
using System.Linq;

namespace Portal.Data.Entity
{
    [Table(Name = "dbo.BannerGroup"), Serializable, DataContractAttribute]
    public class BannerGroup : BaseObject
    {

        #region Properties

        [ColumnAttribute(Name = "ID", IsPrimaryKey = true, IsDbGenerated = true)]
        [DataMemberAttribute(Order = 1)]
        public int ID { get; set; }

        [ColumnAttribute(Name = "Banner_ID")]
        [DataMemberAttribute(Order = 2)]
        public int BannerID { get; set; }

        [ColumnAttribute(Name = "Group_ID")]
        [DataMemberAttribute(Order = 3)]
        public int GroupID { get; set; }

        [ColumnAttribute(Name = "Sort")]
        [DataMemberAttribute(Order = 4)]
        public int Sort { get; set; }


        #endregion
        #region Methods
        public static BannerGroup FindByPrimaryKey(object objectid)
        {
            return FindByPrimaryKey<BannerGroup>(objectid);
        }
        public static int RemoveByBanner(int bannerId)
        {
            return LINQHelper.ExecuteNonQuery("DELETE BannerGroup WHERE Group_ID = {0}", bannerId);
        }
        public static int RemoveByGroup(int groupId)
        {
            return LINQHelper.ExecuteNonQuery("DELETE BannerGroup WHERE Group_ID = {0}", groupId);
        }
        public static BannerGroup FindByKeys(int bannerId, int position)
        {
            const string sql = "select * from BannerGroup where Banner_ID={0} and Group_ID={1}";
            return LINQHelper.GetFirst<BannerGroup>(sql, bannerId, position);
        }
        public static IList FindByBanner(int bannerId)
        {
            const string sql = "select * from BannerGroup where Banner_ID={0} order by Sort";
            return LINQHelper.GetList<BannerGroup>(sql, bannerId);
        }
        #endregion Methods

    }
}
